package com.tutorial.bf.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;

/**
 * Bean工厂后处理器-BeanDefinitionRegistryPostProcessor
 *
 * @ClassName MyBeanDefinitionRegistryPostProcessor
 * @Description Bean工厂后处理器-BeanDefinitionRegistryPostProcessor
 * @Author G
 * @Date 2025/3/11 15:05
 */
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        System.out.println("执行了MyBeanDefinitionRegistryPostProcessor的postProcessBeanDefinitionRegistry方法");
        // 创建BeanDefinition
        BeanDefinition beanDefinition = new RootBeanDefinition();
        beanDefinition.setBeanClassName("com.tutorial.bf.dao.impl.PersonDaoImpl");
        registry.registerBeanDefinition("personDao", beanDefinition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("执行了MyBeanDefinitionRegistryPostProcessor的postProcessBeanFactory方法");
    }
}
